$(document).ready(function(){
	$('.carousel').carousel().bind('slid', function(){
		var xy = $('.carousel-inner .active .xy').val();
		setMap(xy);
	});
	setMap('121.523643,31.232703');

	$('#shops .block').click(function(){
		var num = $('#shops .block').index(this);
		$('.carousel').carousel(num);
		return false;
	});

	$('.carousel-inner img').each(function(k,v){
		var src = $(this).attr('src');
		$('#shops .block:eq('+k+')').html('<img src="'+src+'" /><span class="badge badge-inverse">'+(k+1)+'</span>');
	});
	
	$('#shops').fadeIn();
	
});

function setMap(xy){
    var map = new BMap.Map("map"); // 创建地图实例
    eval('var point = new BMap.Point('+xy+');');
    map.centerAndZoom(point, 18); // 初始化地图，设置中心点坐标和地图级别
    
    
	var marker = new BMap.Marker(point);  // 创建标注
	map.addOverlay(marker);              // 将标注添加到地图中
	marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
    
	map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
	map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}));  //右上角，仅包含平移和缩放按钮
	map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_LEFT, type: BMAP_NAVIGATION_CONTROL_PAN}));  //左下角，仅包含平移按钮
	map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_ZOOM}));  //右下角，仅包含缩放按钮
    
    
	map.enableScrollWheelZoom();    //启用滚轮放大缩小，默认禁用
	map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用
}